<template>
  <div>
    <div class="header">
      <van-nav-bar title="提交订单" @click-left="$router.push('/cart')">
        <template #left>
          <van-icon name="arrow-left" size="26" color="#000" />
        </template>
      </van-nav-bar>
    </div>
    <div class="main">
      <div class="name-a">
        <van-icon name="location-o" @click="doUpdate" />
        <p>
          
          <span>{{ name }}{{ tel }}</span><br>
          <span>{{address}}</span>
        </p>

        <div @click="$router.push('/address')"><van-icon name="arrow" /></div>
        </div>
        <div  class="mainbox">
          <van-swipe-cell v-for="item in list" :key="item.proid">
            <van-checkbox v-model="checked"></van-checkbox>
            <van-card
             
              :price="item.originprice"
             
              :title="item.proname"
              
              class="goods-card"
              :thumb="item.img1"
            />
            <template #right>
              <van-button
                square
                text="删除"
                type="danger"
                class="delete-button"
              />
            </template>
          </van-swipe-cell>
        </div>
           <div class="submit">
          <van-submit-bar
          
            button-text="支付"
            @submit="onSubmit"
          >
            <van-checkbox v-model="isAll">全选</van-checkbox>
          </van-submit-bar>
        </div>
      </div>
   
  </div>
</template>

<script>
import { getDefaultAddress } from "../api/address";
import { getConfirmOrder,getOrder,getUpdateOrder } from "../api/submit";
export default {
  data() {
    return {
      name: "",
      tel: "",
      list: "",
      address:"",
      checked:true,
      isAll:true
    };
  },
  methods: {
    doUpdate(){
      getUpdateOrder(localStorage.getItem("userid")).then((data)=>{console.log(data)})
    },
    onSubmit(){
      
     getOrder({userid:localStorage.getItem("userid")}).then((data)=>{
      console.log(data)
      this.$router.push("/pay")
     })
  }
  },
  created() {
    getDefaultAddress({ userid: localStorage.getItem("userid") }).then(
      (data) => {
        console.log(data);
        this.name = data.data.data[0].name;
        this.tel = data.data.data[0].tel;
        this.address=data.data.data[0].province+data.data.data[0].city+data.data.data[0].county
      }
    ),
  
      getConfirmOrder({
        userid: localStorage.getItem("userid"),
        time: this.$route.params.time,
      }).then((res) => {
        this.list = res.data.data;
        console.log(res.data.data);
      });

     
  },
};
</script>

<style scoped>
.name-a {
  margin: 0.2rem auto;
  padding: 0.1rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.name-a div {
  font-size: 0.26rem;
}
::v-deep .van-swipe-cell__wrapper {
  display: flex;
  background: #fff;
}
::v-deep .van-checkbox {
  width: 0.3rem;
  background: #fff;
}
::v-deep .van-card {
  flex: 1;
}
  .goods-card {
    margin: 0;
    background-color: white;
  }

  .delete-button {
    height: 100%;
  }


.submit .van-checkbox {
 width: 3rem;
}
</style>